package singleton;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * 功能:
 * 作者: ldl
 * 时间: 2016-08-12 10:54
 */
public class Main {

    public static void main(String[] args) {

        ExecutorService executorService = Executors.newCachedThreadPool();

        List<Future<Singleton>> futures = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            futures.add(executorService.submit(new Task()));
        }


        executorService.shutdown();

        try {
            executorService.awaitTermination(1, TimeUnit.DAYS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        try {
            Singleton singleton = futures.get(0).get();
            for (int i = 1; i < futures.size(); i++) {
                Future<Singleton> future = futures.get(i);
                System.out.println(singleton == future.get());

            }
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }

    }
}
